package controller;

import gui.TokenGetter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import client.TokenClient;

import model.dao.AccountDAO;

public class CbbUserAction implements ActionListener {

	private TokenGetter gui;
	private AccountDAO dao;
	private TokenClient client;

	public CbbUserAction(TokenGetter gui, TokenClient client) {
		this.gui = gui;
		this.client = client;
		dao = new AccountDAO();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String accountName = (String) gui.getCb_user().getSelectedItem();
		int pin;
		gui.getTxt_pin().setText(
				(pin = dao.getAccount(accountName).getPin()) + "");

		client.setUsername(accountName);
		client.setPin(pin);
		
		gui.getTxt_token().setText(client.getToken() + "");
		gui.getPb_countDown().setValue(60);
	}

}
